Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Output Chances Deterministic #2565

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

ghzdude
Copy link
Contributor

@ghzdude ghzdude commented Aug 4, 2024

What

Changes the chanced output logic to be more deterministic instead of purely relying on pseudo-rng.
Adds the ability to use fractions as a chance.

Implementation Details

Chances are made deterministic by caching failed chances when rolling to add to it on the next roll. A role is considered successful if the chance + cached chance exceeds the entry's max chance. The OR chance logic also has the added behavior of succeeding several times if the chance is many times over the max chance.

Cached chances are stored in ARL as a Object2Int map, and is serialized to NBT. If a chanced entry is rolled for the first time, a random number between [0,entry.getMaxChance()) is returned, acting as an initial offset. The cache is cleared when a new recipe is found and is different from the previous recipe.

added extra methods to RecipeBuilder to interpret a string as a fractional chance, allowing for irrational fractions to be used as chances. the fraction is split into numerator and denominator, and then scaled up to the max chance (10,000) to make adding chance boosts easier.

Outcome

death to rng

@ghzdude ghzdude added the type: refactor Suggestion to refactor a section of code label Aug 4, 2024
@ghzdude ghzdude requested a review from a team as a code owner August 4, 2024 00:39
make `passesChance()` defualt for override
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Suggestion to refactor a section of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant